
package uk.ac.cam.cl.oscar.MMS_server;

import java.io.IOException;
import java.io.BufferedInputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class SendPremiumSMS {
    
    public static void send(String text, String phoneNo, String network, String charge){
        java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
       
        String userName = "skunkymonkey"; //Username for gateway
        String password = "asdfghjk1"; //Password for gateway
        String tariff = charge; //Amount to charge
       
        try{
            
           /*Create URL to post to, including parameters*/
           String s = "https://secure.itagg.com/smsg/sms_prem.mes?usr=" + userName + "&pwd=" + password + "&tariff=" + tariff + "&to=" + phoneNo + ";" + network + "&txt=" + text;
           System.out.printf("%s%n", s); //DEBUG
           URL url = new URL(s);
           
           /*Setup HTTP connection*/
           HttpURLConnection conn = (HttpURLConnection)url.openConnection();
           
           /*Set HTTP connection method to POST and send message to gateway by connecting*/
           conn.setRequestMethod("POST");
           conn.setDoOutput(true);
           conn.connect();
           
           /*Receive response from gateway*/
           BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
           while(bis.available() > 0){
                System.out.printf("%c", bis.read());
           }
           System.out.printf("%n");
           bis.close();
           
        }
        catch(IOException e){
            System.out.printf("IOException Occurred in SendSMS");
        }
        
    }

}
